//
//  HZWecomeVc.m
//  微博 OC
//
//  Created by 黑眼圈 on 16/4/21.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "HZWecomeVc.h"

//define this constant if you want to use Masonry without the 'mas_' prefix
#define MAS_SHORTHAND
//define this constant if you want to enable auto-boxing for default syntax
#define MAS_SHORTHAND_GLOBALS



#import <Masonry/Masonry.h>
#import <SDWebImage/UIImageView+WebCache.h>
#import "HZOAuthVM.h"

@interface HZWecomeVc ()

@property(nonatomic,strong)UIImageView*  icon;
@property(nonatomic,strong)UILabel*  nameLabel;

@end

@implementation HZWecomeVc


//视图已经显示完成之后
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
    //约束动画
    [self.icon updateConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(100);
    }];
    
    [UIView animateWithDuration:0.5 animations:^{
        //更新约束
        [self.view layoutIfNeeded];
        
    } completion:^(BOOL finished) {
        
//        NSLog(@"登录成功");
        
        
        //发布通知跳转控制器
        [[NSNotificationCenter defaultCenter] postNotificationName:@"wecome" object:nil];
    }];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];

    
    self.view.backgroundColor = [UIColor colorWithWhite:237/255.0 alpha:1];
    
    [self setupUI];
    
}







-(void)setupUI{
    
//    NSString* imgName = [HZOAuthVM sharedOAuth].model.profile_image_url;
//    
//    [self.icon sd_setImageWithURL:[NSURL URLWithString:@"avatar_default_big"]];
    
//    //跟图片一样大小
//    [self.icon sizeToFit];
    
    //添加子控件
    [self.view addSubview:self.icon];
    [self.view addSubview:self.nameLabel];
    
    
    
    // 约束
    [self.icon makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.height.equalTo(80);
        make.top.equalTo(200);
        make.centerX.equalTo(self.view.centerX);
 
        
    }];
    
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.icon.centerX);
        make.top.equalTo(self.icon.bottom).offset(10);
        
    }];
    
    
    
}



#pragma mark -
#pragma mark     懒加载控件
-(UIImageView *)icon{
    if (_icon == nil) {
        
        _icon = [[UIImageView alloc]init];
//        

        _icon.image = [UIImage imageNamed:@"avatar_default_big"];
        

    
        NSString* imgName = [HZOAuthVM sharedOAuth].model.profile_image_url;

        //网络获取头像图片
        [_icon sd_setImageWithURL:[NSURL URLWithString:imgName]];
        
        _icon.layer.cornerRadius = 40;
        _icon.layer.masksToBounds = YES;
    
        
    }
    return _icon;
}

-(UILabel *)nameLabel{
    if (_nameLabel  == nil) {
        _nameLabel = [[UILabel alloc]init];
        
        _nameLabel.textAlignment = NSTextAlignmentCenter;
        _nameLabel.font = [UIFont systemFontOfSize:14];
        
        _nameLabel.text = [HZOAuthVM sharedOAuth].model.name;
        
        
    }
    return _nameLabel;
}


@end
